<!DOCTYPE html>
<html>
<head>
	<title>已部署流程</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <script type="text/javascript">
        var path = window.document.location.href;
        var pathName = window.document.location.pathname;
        var hostPath = path.substring(0, path.indexOf(pathName));
        var projectName = pathName.substring(0, pathName.substr(1).indexOf("/") + 1);
        document.write('<scr' + 'ipt src="' + projectName + '/js/html/header.js"></scr'+'ipt>');
    </script>
</head>
<body>
	<table id="dg" style="width: auto; height: auto" fitColumns="true">
		<thead>
			<tr>
			<th field="deploymentId" align="right" width="100" 
				data-options="
				sortable:true,
				remoteSort:false
				">部署ID</th>
			<th field="key" align="right" width="100" 
				data-options="
				sortable:true,
				remoteSort:false
				">流程标识(流程启动参数)</th>
			<th field="name" align="right" width="100" 
				data-options="
				sortable:true,
				remoteSort:false
				">流程名称</th>
			<th field="version" align="right" width="60" 
				data-options="
				sortable:true,
				remoteSort:false
				">流程版本</th>
			<th field="resourceName" align="right" width="100" 
				data-options="
				sortable:true,
				remoteSort:false
				">流程部署模型</th>
			</tr>
		</thead>
	</table>
	<div id="dg-buttons" style="height: auto">
		<div style="margin-bottom:5px">
            <a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-remove',plain:true"
                onclick="deleteDefinition()">删除</a>
        </div>
		<div>
			<span>&nbsp;&nbsp;&nbsp;&nbsp;选择:</span>
			<input type="text" id="searchKey" name="searchKey" class="easyui-combobox" />
			<span>等于:</span>
			<input type="text" id="searchValue" name="searchValue" class="easyui-validatebox" />
			<a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-search" onclick="dgop.find()">查询</a>
		</div>
	</div>
	<!--隐藏的文本框-->
	<div id="win" class="easyui-window" title="工作流任务" style="width: 800px; height: 450px" closed="true" data-options="iconCls:'icon-save',modal:true">
		<div id="centers" data-options="region:'center',title:'center title'" style="padding: 5px; background: #eee; height: 90%"></div>
	</div>
	
	<div id="dlg-Details" class="easyui-window" closed="true" style="width: 730px; height: 280px; padding: 10px 10px;"></div>
	<script>
		var initd = {
			queryDataURL : "/workflow/process/definition/query",
			saveDataURL : "/workflow/process/start",
			dg : $('#dg')
		};
		function quotaEffect() {
		    var selectedRows = $("#dg").datagrid("getSelections");
		    if (selectedRows.length == 0) {
		        $.messager.alert("系统提示", "请选择要启动的流程！");
		        return;
		    }
		    
		    var data0 = $("#dg").serialize();
		    $.messager.confirm("系统提示", "您确定要启动<font color=red>" + selectedRows.length + "</font>流程吗？", function(r) {
		        if (r) {
		        	$.ajax({
		        		type:"POST",
		        		dataType:"json",
		        		contentType : "application/json;charset=utf-8",
		        		url :projectName+initd.quotaEffectDataURL,
		        		data:JSON.stringify({taskid : selectedRows[0].id_}),
		        		beforeSend : function() {
		                },
		        		success : function(result) {
		        			if (result.success) {
			                    $.messager.alert("系统提示", "流程已启动！");
			                    $("#dg").datagrid("reload");
			                } else {
			                	if(!jQuery.isEmptyObject(result.message)){
			                		$.messager.alert("系统错误", result.message);
			                	}else{
			                		$.messager.alert("系统错误", result);
			                	}
			                    return;
			                }
		                },
		        		error:function(err, status){
		        			errorMsgAlert(err);
		        			$.messager.progress("close");
		        		}
		        	});

		        }
		    });
		}
		
		function act(val, row, index) {
			return '<a onclick="doWorkFlow(\''
					+ row['key']
					+ '\')">启动</a>';
		}

		function doWorkFlow(processkey) {
			$("#win").window("open");
			var hrefs = '<iframe id="son" src="'+projectName+'/html/workflow/startwork.html'
					+ '?processkey='
					+ processkey
					+ '" allowTransparency="true" style="border:0;width:99%;height:99%;padding-left:2px;" frameBorder="0"></iframe>';
			$("#centers").html(hrefs);
		}
		
		
		function deleteDefinition() {
            var selectedRows = $("#dg").datagrid("getSelections");
            if (selectedRows.length == 0) {
                $.messager.alert("系统提示", "请选择要删除的数据！");
                return;
            }
            
            var removeData = selectedRows[0]

            var deleteURL = "/workflow/process/"+removeData.deploymentId;

            $.messager.progress();
            
            $.messager.confirm("系统提示", "您确定要删除这<font color=red>" + selectedRows.length + "</font>条数据吗？", function (r) {
                if (r) {
                	$.ajax({
                        type: "DELETE",
                        dataType: "json",
                        url: projectName + deleteURL,
                        success : function(result) {
                            $.messager.progress("close");
                			if (result.success) {
        	                    $.messager.alert("系统提示", "数据已成功删除！");
        	                    $("#dg").datagrid("reload");
        	                } else {
        	                	if(!jQuery.isEmptyObject(result.message)){
        	                		$.messager.alert("系统错误", result.message);
        	                	}else{
        	                		$.messager.alert("系统错误", result);
        	                	}
        	                    return;
        	                }
                        },
                		error:function(err, status){
                			errorMsgAlert(err);
                			$.messager.progress("close");
                		}
                    });
                }
            });
        }

	</script>
</body>
</html>

